//
//  FQGuideView.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/9/6.
//

import UIKit

class FQGuideView: UIView {
    var popup : KLCPopup!
    
    convenience init() {
        self.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 350 + PreferredValueForNotchedDevice(notchedDevice: 20, otherDevice: 0)))
        
        backgroundColor = .white
        clipsToBounds = true
        layer.cornerRadius = 15
        layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
        
        let titleLb = QMUILabel(font: .mSFont(20), textColor: .color51)
        titleLb.text = "感谢您信任并使用宝银钱包"
        addSubview(titleLb)
        titleLb.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.top.equalTo(40)
        }
        
        let detailLb = QMUILabel(font: .rSFont(14), textColor: .color102)
        detailLb.numberOfLines = 0
        detailLb.text = "我们非常重视您的隐私保护和个人信息保护，请您认真阅读《宝银钱包隐私权政策》全部条款，了解我们为保护您的信息所做的具体措施及承诺，同意并接受全部条款后再开始使用我们的服务。\n\n我们将在账户注册、借款授信等业务场景中收集、使用信息，包括姓名、手机号码、身份信息、银行卡信息等。在您逐步深入使用省呗的过程中，您将需要根据不同的业务场景开启相应的设备权限，如位置信息、相机权限等。"
        addSubview(detailLb)
        detailLb.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.top.equalTo(titleLb.snp.bottom).offset(16)
        }
        
        let agreeBtn = QMUIFillButton(fill: .colorMain, titleTextColor: .white)
        agreeBtn.setTitle("同意，进入宝银钱包", for: .normal)
        agreeBtn.titleLabel?.font = .mSFont(14)
        agreeBtn.cornerRadius = 8
        agreeBtn.tag = 1
        agreeBtn.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
        addSubview(agreeBtn)
        
        agreeBtn.snp.makeConstraints { make in
            make.right.equalTo(-20)
            make.left.equalTo(SCREEN_WIDTH / 2 + 10)
            make.top.equalTo(detailLb.snp.bottom).offset(40)
            make.height.equalTo(46)
        }
        
        let refuseBtn = QMUIFillButton(fill: .colorMain.withAlphaComponent(0.09), titleTextColor: .color149)
        refuseBtn.setTitle("我再想想", for: .normal)
        refuseBtn.titleLabel?.font = .mSFont(14)
        refuseBtn.cornerRadius = 8
        refuseBtn.tag = 2
        refuseBtn.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
        addSubview(refuseBtn)
        
        refuseBtn.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.width.equalTo(SCREEN_WIDTH / 2 - 30)
            make.top.equalTo(detailLb.snp.bottom).offset(40)
            make.height.equalTo(46)
        }
    }

    @objc func buttonClick(_ button : QMUIButton) {
        if button.tag == 2 {
            abort()
        }
        popup.dismiss(true)
    }
    
    func show() {
        popup = KLCPopup(contentView: self, showType: .slideInFromBottom, dismissType: .slideOutToBottom, maskType: .dimmed, dismissOnBackgroundTouch: false, dismissOnContentTouch: false)
        popup.show(with: KLCPopupLayout(horizontal: .center, vertical: .bottom))
    }
}
